<template>
	<view>
		<view class="cu-bar bg-white solid-bottom justify-center shadow">
			<view class='all'>
				<view class="bar">
					<!-- 显示年月 -->
					<view class="date">
						<view class="leftArrow" @tap="handleCalendar" data-handle="prev"></view>
						<picker mode="date" fields="year" :value="curDate" :start="startDate" :end="endDate" @change="dateChange">
							<view class="picker">
								<view class="solid-bottom text-lg">
									<text class="text-black">{{curDate}}年</text>
								</view>
							</view>
						</picker>
						<view class="rightArrow" @tap="handleCalendar" data-handle="next"></view>
					</view>
				</view>
			</view>
		</view>

		<!-- 列表 -->
		<view class="cu-bar bg-white solid-bottom margin-top-sm">
			<view class="action">
				<text class="cuIcon-title text-brown"></text> 查询列表
			</view>
		</view>
		<scroll-view>
			<form>
				<view v-for="(item,index) in landList" :key="index">
					<view class="cu-form-group" :class="index==0?'':'margin-top'">
						<view class="title">{{item.landName}}</view>
						<view>
							<button class="cu-btn bg-green shadow" @tap="navToDetail" :data-landid="item.landId" :data-startdate="item.startDate"
							 :data-enddate="item.endDate">档案详情</button>
						</view>
					</view>
					<view class="cu-form-group">
						<view class="title">位置</view>
						<input :value="item.landLocation" name="input" disabled></input>
					</view>
					<view class="cu-form-group">
						<view class="title">面积</view>
						<input :value="item.landArea" name="input" disabled>公顷</input>
					</view>
				</view>
			</form>
		</scroll-view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				startDate: "" + (new Date().getFullYear() - 30),
				endDate: "" + new Date().getFullYear(),
				curDate: "" + new Date().getFullYear(),
				landList: []
			}
		},
		onLoad: function() {},
		methods: {
			dateChange: function(e) {
				this.curDate = e.detail.value
				this.getListData()
			},
			handleCalendar: function(e) {
				if (e.currentTarget.dataset.handle === 'prev') {
					if (parseInt(this.startDate) >= parseInt(this.curDate)) {
						return
					}
					this.curDate = "" + (parseInt(this.curDate) - 1)
					this.getListData()
				} else {
					if (parseInt(this.curDate) >= parseInt(this.endDate)) {
						return
					}
					this.curDate = "" + (parseInt(this.curDate) + 1)
					this.getListData()
				}
			},
			getListData: function() {
				//console.log(this.curDate)
				//console.log(typeof(this.curDate))
				uni.showLoading({
					title: '加载中'
				});
				uni.request({
					url: this.$config.apiUrl + '/dasContractController/contractLandList',
					data: {
						userId: this.$store.getters.userid,
						year: this.curDate
					},
					method: "GET",
					success: (res) => {
						uni.hideLoading();
						//console.log(res)
						if (res.data.ok) {
							this.landList = res.data.data
						} else {
							this.landList = []
							uni.showToast({
								icon: "none",
								title: '获取承租地块列表失败',
								duration: 1000
							});
						}
					},
					fail() {
						uni.hideLoading();
						uni.showModal({
							title: '提示',
							content: "获取承租地块列表失败",
							showCancel: false
						});
					}
				});

			},
			navToDetail: function(e) {
				var dataset = e.currentTarget.dataset
				uni.navigateTo({
					url: './zzda_detail?landId=' + dataset.landid + '&startDate=' + dataset.startdate + '&endDate=' +
						dataset.enddate
				})
			}
		}
	}
</script>

<style>
	.menu {
		width: 88rpx;
		height: 88rpx;
		border-radius: 88rpx;
		line-height: 88rpx;
		text-align: center;
		justify-content: center;
		background-color: #FF0036;
		color: #FFFFFF;
		font-size: 50rpx;
		padding: 0;
	}

	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}

	.all {
		width: 92%;
		box-shadow: 0 5px 8px -1px rgba(175, 171, 171, 0.2);
		border-radius: 20rpx;
		top: 225rpx;
		left: 30rpx;
		background-color: white;
	}

	.all .bar {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		padding: 10rpx;
	}

	.all .bar image {
		width: 50rpx;
		height: 50rpx;
	}

	.date {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		font-size: 38rpx;
		font-weight: 500;
		color: rgba(51, 51, 51, 1);
		margin: 0px auto;
	}

	.leftArrow {
		width: 0;
		height: 0;
		border-top: 9px solid transparent;
		border-right: 12px solid #8dc63f;
		border-bottom: 9px solid transparent;
		margin-right: 20rpx;
	}

	.rightArrow {
		width: 0;
		height: 0;
		border-top: 9px solid transparent;
		border-left: 12px solid #8dc63f;
		border-bottom: 9px solid transparent;
		margin-left: 20rpx;
	}
</style>
